<template>
  <!-- 个人中心 -->
  <div class="personalinfo">
    <MyHead title="个人中心"></MyHead>
    <div class="top-box">
      <div class="title flexb">
        <div class="flexb">
          <div><van-icon name="award" color="#FF9000 " size="20" style="margin-right: 5px;"/></div>
          <div>{{ personalInfor.name }}</div>
        </div>
        <div @click="editInfo"><van-icon name="records-o" size="20" color="#ffffff " /></div>
      </div>
      <div class="text-style">所属院系：{{ personalInfor.college_name }}</div>
      <div class="text-style">入学年份：{{ personalInfor.grade }}</div>
      <div class="text-style">性别：{{ personalInfor.gender }}</div>
    </div>
    <div class="content-box">
      <div class="list-box">
        <div class="item-box flexb" @click="gorRecord">
          <div class="flexb">
            <div class="icon-style">
              <van-icon name="notes" color="#F4473B " size="20" />
            </div>
            <div>活动参与记录</div>
          </div>
          <div><van-icon name="arrow" color="#3E3D3D " /></div>
        </div>
        <div class="item-box flexb" @click="goMedal">
          <div class="flexb">
            <div class="icon-style"><van-icon name="award" color="#FF9000 " size="20" /></div>
            <div>我的勋章</div>
          </div>
          <div><van-icon name="arrow" color="#3E3D3D " /></div>
        </div>
        <div class="item-box flexb" @click="goSchool">
          <div class="flexb">
            <div class="icon-style"><van-icon name="award" color="#3E3D3D " size="20" /></div>
            <div>我的学校</div>
          </div>
          <div><van-icon name="arrow" color="#3E3D3D " /></div>
        </div>
      </div>
    </div>
    <MyTab ></MyTab>
  </div>
</template>
<script>
export default {
  data() {
    return {
      openid: $.cookie("openid"),
      personalInfor:{}
    };
  },
  computed: {},
  methods: {
    /*活动参与记录*/
    async gorRecord(){
      let res = await this.$ajax.getPersoninfo({
        openid: this.openid,
      });
      if (res.code == 1) {
        this.changeUserInfo(res.data);
        this.$router.push({name:'activityRecord'})
      }
       
    },
    /*我的勋章*/ 
    async goMedal(){
      let res = await this.$ajax.getPersoninfo({
        openid: this.openid,
      });
      if (res.code == 1) {
        this.changeUserInfo(res.data);
        this.$router.push({name:'medal'});
      }
        
    },
    async goSchool(){
      let res = await this.$ajax.getPersoninfo({
        openid: this.openid,
      });
      if (res.code == 1) {
        this.changeUserInfo(res.data);
        this.$router.push({name:'schoolindex',query:{depart_code:this.personalInfor.depart_code,name:this.personalInfor.name}})
      }else{
        this.changeRegShow(true)
      }
     
    },
    /*修改个人信息*/ 
    async editInfo(){
      let res = await this.$ajax.getPersoninfo({
        openid: this.openid
      })
      if (res.code == 1) {
        this.changeUserInfo(res.data);
        this.$router.push({name:"editInfoPage"})
      }
    },
    /*获取用户信息*/
    async getUserInfo() {
      let res = await this.$ajax.getPersoninfo({
        openid: this.openid
      })
      if (res.code == 1) {
        this.personalInfor = res.data
        this.changeUserInfo(res.data);
      } 
    }
  },
  mounted() {
    this.getUserInfo();
  },
  created() {
    this.$bus.$on("reload", this.getUserInfo);
  },
};
</script>
<style lang="scss" scoped>
.text-style {
  color: rgb(255, 255, 255);
  font-size: 15px;
  font-family: SourceHanSansSC-regular;
  line-height: 30px;
}
.personalinfo {
  width: 100%;
  min-height: 100vh;
    
  background-color: rgba(249, 249, 249, 1);
  .top-box {
    color: rgb(255, 255, 255);
    line-height: 25px;
    background: linear-gradient(to  right,#F44336 50%  , #B71C1C );
   
    padding: 15px;
    .title {
      
      font-size: 18px;
      text-align: left;
      font-family: SourceHanSansSC-regular;
      font-weight: bold;
      line-height: 40px;
    }
  }
  .content-box {
    padding: 15px;
    .list-box {
      padding: 10px;
      line-height: 40px;
      border-radius: 4px;
      background-color: rgba(255, 255, 255, 1);
      .item-box {
        border-bottom: 0.5px solid #efefef;
        .icon-style {
          margin-right: 5px;
        }
      }
      .item-box:nth-last-child(1){
        border-bottom: none;
      }
    }
  }
}
</style>